package L7.L713;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * todo
 *
 * @author: luolidong
 * @create: 2021-07-12 22:38
 * @version: 1.0
 */
public class Demo {
    int len;
    List<List<String>> list;
    public List<List<String>> partition(String s) {
        list=new ArrayList<>();
        if(s.length()==0) return list;
        //转数组
        char[] charArray = s.toCharArray();
        len=s.length();

        dfs(charArray, 0, new ArrayList<>());
        return list;
    }

    public void dfs(char[] charArray,int index,List<String> clist){
        if(index==len){
            list.add(new ArrayList<>(clist));
            return;
        }
        for (int i = index; i <len ; i++) {
            if(!isHuiWei(charArray, index, i)) continue;
            //int[] offset count
            clist.add(new String(charArray,index,i-index+1));
            dfs(charArray,i+1,clist);
            clist.remove(clist.size()-1);
        }
    }
    /**
    * @Description: 判断回文
    * @Param: [charArray, left, right]
    * @return: boolean
    */
    public boolean isHuiWei(char[] charArray,int left,int right){
        while (left<right){
            if(charArray[left]!=charArray[right]){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }

    public static void main(String[] args) {
        Demo demo = new Demo();
        List<List<String>> aabbcac = demo.partition("aabbcac");
        System.out.println(aabbcac);
    }
}
